#include <iostream>
#include <vector>
#include <BinaryTree.hpp>

using namespace std;
class Solution
{
public:
    TreeNode *sortedArrayToBST(vector<int> &nums)
    {
        if (nums.empty())
            return nullptr;
        return sortedArrayToBST(nums, 0, nums.size() - 1);
    }

    TreeNode *sortedArrayToBST(vector<int> &nums, int left, int right)
    {
        if (right - left < 0)
        {
            return nullptr;
        }
        int mid = left + (right - left) / 2;
        cout << left << ":" << mid << ":" << right << endl;
        TreeNode *root = new TreeNode(nums[mid]);
        root->left = sortedArrayToBST(nums, left, mid - 1);
        root->right = sortedArrayToBST(nums, mid + 1, right);
        return root;
    }
};

int main()
{
    cout << "Code108" << endl;
    Solution s;
    vector<int> nums = {1, 2, 3, 4, 5, 6, 7};
    TreeNode *root = s.sortedArrayToBST(nums);
    return 0;
}